package com.lin.blog.controller;


import com.lin.blog.entity.UserLike;
import com.lin.blog.service.IUserLikedService;
import com.lin.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lin
 * @since 2020-03-08
 */
@Api(tags = "UserLiked接口")
@RestController
@RequestMapping("/userLiked")
public class UserLikedController {


    @Autowired
    private IUserLikedService userLikedService;



    /**
     *  通过 likedArticleId likedUserId 获取是否点赞收藏
     * @param likedArticleId
     * @param likedUserId
     * @return
     */
    @ApiOperation("获取是否点赞收藏")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "likedArticleId", value = "文章ID",required = true),
            @ApiImplicitParam(name = "likedUserId", value = "用户ID", required = true)})
    @GetMapping("/{likedArticleId}/{likedUserId}")
    public Result getByLikedUserIdAndLikedArticleId(@PathVariable("likedArticleId") Long likedArticleId,
                                   @PathVariable("likedUserId") Long likedUserId){
        UserLike userLike = userLikedService.getByLikedUserIdAndLikedArticleId(likedArticleId, likedUserId);
        return Result.success(userLike);
    }


    /**
     * 点赞喜欢
     * @param userLike
     * @return
     */
    @ApiOperation("点赞喜欢")
    @PostMapping("/like")
    public Result saveUserLike(@RequestBody  UserLike userLike){
        return userLikedService.saveUserLike(userLike);
    }

    /**
     * 点赞不喜欢
     * @param userLike
     * @return
     */
    @ApiOperation("点赞不喜欢")
    @PostMapping("/unlike")
    public Result saveUnUserLike(@RequestBody  UserLike userLike){
        return userLikedService.saveUnUserLike(userLike);
    }







}
